//
//  BanBu_AlertView.m
// Halfarea
//
//  Created by Wang Xj on 14-3-3.
//
//

#import "BanBu_AlertView.h"
#import "AppDataManager.h"

@implementation BanBu_AlertView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
    }
    return self;
}

-(void)dealloc
{
    [_textLabel release];
    [super dealloc];
}

//初始化警告提示lable,并设置背景为黑色透明
-(void)initWithText:(NSString *)text
{
    //背景view
    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(290, 1000)lineBreakMode:kTextLineBreakByWordWrapping];
    UIView * backView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 300, size.height)];
    backView.alpha = 0.5;
    backView.backgroundColor = [UIColor grayColor];
    backView.layer.cornerRadius = 10;
    backView.userInteractionEnabled = YES;
    UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
    [backView addGestureRecognizer:longPress];
    [longPress release];
    
    [self addSubview:backView];
    [backView release];
    
    //警告语label
    _textLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, size.width, size.height)];
    
    //根据语言版本设置开始位置
    if ([[MyAppDataManager getLanguageSubmitToServer] isEqualToString:@"en"])
    {
        _textLabel.frame = CGRectMake(24, 0, size.width, size.height);
    }
    
    _textLabel.text = text;
    _textLabel.numberOfLines = 0;
    _textLabel.backgroundColor = [UIColor clearColor];
    _textLabel.textColor = [UIColor whiteColor];
    _textLabel.alpha = 0.65;
    _textLabel.textAlignment = kTextAlignmentLeft;
    _textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _textLabel.font = [UIFont systemFontOfSize:14];
    
    [self addSubview:_textLabel];
}

//长按删除
-(void)longPress:(UILongPressGestureRecognizer *)longPress
{
    if (longPress.state == UIGestureRecognizerStateBegan)
    {
        UIAlertView * alert = (UIAlertView *)[self viewWithTag:1001];
        if (alert)
        {
            return;
        }
        
        //不重复提示
        alert = [[[UIAlertView alloc]initWithTitle:nil message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"cancelNotice", nil) otherButtonTitles:NSLocalizedString(@"deleteButton", nil), nil] autorelease];
        alert.tag = 1001;
        
        [alert show];
    }
}

//#pragma mark - UIAlertViewDelegate
//-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
//{
//    if (buttonIndex)
//    {
//        if ([_delegate respondsToSelector:@selector(removeAlertView:)])
//        {
//            [_delegate removeAlertView:self];
//        }
//    }
//}

@end
